<template>
  <a-dropdown placement="bottomRight">
    <div class="header-avatar" style="cursor: pointer">
      <a-avatar class="avatar" size="small" shape="circle" :src="user.avatar"/>
      <span class="name">{{user.name}}</span>
    </div>
    <div class="avatar-menu" slot="overlay">
      <p class="avatar-menu-head"><span>Admin</span><a-button @click="info(1)" type="link"><a-icon type="edit" /> 编辑</a-button></p>
      <p class="avatar-menu-subtitle">机构信息</p>
      <p class="avatar-menu-row"><span>机构名称：蓝点通信</span><span>联系人：张远</span></p>
      <p class="avatar-menu-row">联系电话：15826967811</p>
      <hr class="hr-d">
      <p class="avatar-menu-subtitle">个人信息</p>
      <p class="avatar-menu-row"><span>用户名：Admin</span><span>姓名：张远</span></p>
      <p class="avatar-menu-row">联系电话：15826967811</p>
      <hr class="hr-d">
      <p class="avatar-menu-btn">
        <a-button type="primary" @click="info(2)" :ghost="true">
          修改密码
        </a-button>
        <a-button @click="logout">
          退出登录
        </a-button>
      </p>
    </div>
  </a-dropdown>
</template>

<script>
import {mapGetters} from 'vuex'
import {logout} from '@/services/user'

export default {
  name: 'HeaderAvatar',
  computed: {
    ...mapGetters('account', ['user']),
  },
  methods: {
    info(tab) {
      this.$router.push({path: '/system/personal', query: {tab}});
    },
    logout() {
      logout()
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less">
  .header-avatar{
    display: inline-flex;
    .avatar, .name{
      align-self: center;
    }
    .avatar{
      margin-right: 8px;
    }
    .name{
      font-weight: 500;
    }
  }
  .avatar-menu{
    width: 400px;
    background: #fff;
    box-shadow: 1px 1px 10px #d9d9d9;
    padding: 15px 15px 1px 15px;
    &-head{
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0;
      margin: 0;
      &:first-child{
        color: #1890ff;
        font-size: 18px;
      }
    }
    &-subtitle{
      font-size: 14px;
      color: #8c8c8c;
      margin: 0;
      padding: 5px 0 8px 0;
    }
    &-row{
      display: flex;
      justify-content: space-between;
      margin: 0;
      padding: 0 0 8px 0;
      span{
        flex: 1;
        text-align: left;
      }
    }
    &-btn{
      display: flex;
      justify-content: space-between;
      button{
        width: 130px;
        border-radius: 25px;
      }
    }
  }
  .hr-d{
    height:1px;border:none;border-top:1px dashed #999999;
  }
</style>
